package entities;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Column;
import javax.persistence.Table;

@Entity
@Table(name = "MEDEWERKER")
@AttributeOverrides({
    @AttributeOverride(name = "naam",           column = @Column(name="naam")),
    @AttributeOverride(name = "voornaam",       column = @Column(name="voornaam")),
    @AttributeOverride(name = "tussenvoegsel",  column = @Column(name="tussenvoegsel")),
    @AttributeOverride(name = "geboortedatum",  column = @Column(name="geboortedatum")),
    @AttributeOverride(name = "postcode",       column = @Column(name="postcode")),
    @AttributeOverride(name = "telefoonnummer", column = @Column(name="telefoonnummer")),
    @AttributeOverride(name = "email",          column = @Column(name="email")),
    @AttributeOverride(name = "rekeningnummer", column = @Column(name="rekeningnummer")),
    @AttributeOverride(name = "gebruikersnaam", column = @Column(name="gebruikersnaam")),
    @AttributeOverride(name = "inlogcode",      column = @Column(name="inlogcode"))
})
public class Medewerker extends Persoon
{
	private Set<Rol> rollen;

	// Constructors
	
	/**
	 * Constructor voor Hibernate
	 */
	@SuppressWarnings("unused")
	private Medewerker()
	{
		super();
		rollen = new HashSet<Rol>();
	}
	public Medewerker(String naam, String voornaam, Date geboortedatum, String rekeningnummer, String gebruikersnaam, String inlogcode, int bsn)
	{
		super(naam, voornaam, geboortedatum, rekeningnummer, gebruikersnaam, inlogcode, bsn);
		rollen = new HashSet<Rol>();
	}
	
	// Getters en Setters
	
	@ManyToMany(
			cascade = CascadeType.ALL)
	@JoinTable(
			name = "MEDEWERKER_ROL",
			joinColumns = { @JoinColumn(name = "medewerker_id") },
			inverseJoinColumns = { @JoinColumn(name = "rol_id") })
	public Set<Rol> getRollen()
	{
		return rollen;
	}
	public void setRollen(Set<Rol> rollen)
	{
		this.rollen = rollen;
	}
	
	// Methoden
	
	public boolean hasRol(Rol rol)
	{
		return rollen.contains(rol);
	}
	
	public void addRol(Rol rol)
	{
		rollen.add(rol);
	}
	
	public void removeRol(Rol rol)
	{
		rollen.remove(rol);
	}
	
	public boolean hasAnyRol()
	{
		return !rollen.isEmpty();
	}
	
	@Override
	public String toString()
	{
		return super.toString();
	}
}
